package com.briup.cms.service.impl;

import com.briup.cms.bean.Article;
import com.briup.cms.bean.extend.ArticleExtend;
import com.briup.cms.dao.ArticleMapper;
import com.briup.cms.service.IArticleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ArticleServiceImpl implements IArticleService {
    @Resource
    private ArticleMapper articleMapper;

    @Override
    public List<Article> findAll() { return articleMapper.selectAll();
    }

    @Override
    public List<ArticleExtend> findAllWithName() {
        return articleMapper.selectAllWithName();
    }

    @Override
    public String saveOrUpdate(Article article) {
        if (article.getId() != null){
            articleMapper.update(article);
            return "更新成功";
        }
        article.setPublishDate(System.currentTimeMillis());
        articleMapper.insert(article);
        return "保存成功";
    }

    @Override
    public void deleteById(long id) {

        articleMapper.deleteById(id);
    }
}
